#pragma once

#define PID_VERSION "1.1"

#include <inttypes.h>

#define allowLimitMax 1
#define allowLimitMin 2
#define invert 4
#define enabled 8

class PID
{
private:
	double pGain,iGain,dGain;
	double integrator;
	double lastInput;
	double limitMax,limitMin;
	long lastTime;

	char settings;
	
public:
    struct Spid {
        double p,i,d,limitMax,limitMin;
        char settings;
    };
    
	PID();//constructor
	
	//getters
	double getPGain();
	double getIGain();
	double getDGain();
	double getLimitMax();
	double getLimitMin();
	bool isLimitMaxSet();
	bool isLimitMinSet();
	bool isInverted();
	
	//setters
	void setPGain(double newPGain);
	void setIGain(double newIGain);
	void setDGain(double newDGain);
	void setPIDGain(double newPGain, double newIGain, double newDGain);
	void setLimitMax(double newLimitMax);
	void setLimitMin(double newLimitMin);
	void setLimits(double newLimitMin, double newLimitMax);
	void disableMaxLimit();
	void disableMinLimit();
	void disableLimits();
	void zeroOutIntegrator();
	void nullOut();
	void setInverted(bool newInvert);
	void clear();
	
	//actions
	void run(const double &input, double &output, const double &setpoint);
	
	void setFrom(Spid copy);
	void copy(Spid &copy);
};
